<?php

Function get_group_infos($gid, $connect="ok")
{
	$table_groups = $_SESSION['prefix']."groups";
	$req = dbquery("SELECT * FROM $table_groups WHERE gid='$gid'", $connect);
	return (@mysql_fetch_array($req));
}

Function get_group_users($gid)
{ 
	$table_users_auth = $_SESSION['prefix']."users_auth";
	$table_users_groups = $_SESSION['prefix']."users_groups";
	
	$connection = dbconnect();
	$req_1 = dbquery("SELECT uid FROM $table_users_groups WHERE gid='$gid'", $connection);

	if (@mysql_num_rows($req_1))
	{
		$i = -1;
		while ($line = mysql_fetch_array($req_1))
		{
			$i++;
			$req_2 = dbquery("SELECT login FROM $table_users_auth WHERE uid=$line[uid]", $connection);
			$users[$i] = @mysql_result($req_2, 0, "login");
	    }
		mysql_close($connection);
		if (!isset($users))
			return (-1);
		else
			return ($users);
	}
	mysql_close($connection);
	return (-1);
}

Function get_user_groups($uid)
{ 
	$table_users_groups = $_SESSION['prefix']."users_groups";
	$table_groups = $_SESSION['prefix']."groups";
	
	$connection = dbconnect();
	$req_1 = dbquery("SELECT gid FROM $table_users_groups WHERE uid='$uid' AND status='ok'", $connection);
	
	if (@mysql_num_rows($req_1))
	{
		$i = -1;
		while ($line = mysql_fetch_array($req_1))
		{
			$i++;
			$req_2 = dbquery("SELECT title FROM $table_groups WHERE gid='$line[gid]'", $connection);
			$groups[$i] = @mysql_result($req_2, 0, "title");
		}
		mysql_close($connection);
		return ($groups);
	}
	mysql_close($connection);
	return (-1);
}

Function get_gids()
{ 
	$table_groups = $_SESSION['prefix']."groups";
	$req = dbquery("SELECT gid FROM $table_groups WHERE 1");
	
	if (@mysql_num_rows($req))
	{
		$i = -1;
		while ($line = mysql_fetch_array($req))
		{
			$i++;
			$gids[$i] = $line['gid'];
		}
		return ($gids);
	}
	return (-1);
}

Function get_group($gid)
{ 
	$table_groups = $_SESSION['prefix']."groups";
	$req = dbquery("SELECT title FROM $table_groups WHERE gid='$gid'");
  
	if (@mysql_num_rows($req))
		return (mysql_result($req, 0, "title"));
	return (-1);
}

Function get_gid($group)
{ 
	$table_groups = $_SESSION['prefix']."groups";
	$req = dbquery("SELECT gid FROM $table_groups WHERE title='$group'");
  
	if (@mysql_num_rows($req))
		return (@mysql_result($req, 0, "gid"));
	return (-1);
}

?>